#include #include #include using namespace std; #pragma warning( disable : 996 ) void MakeUpperCase(char& c) { const int OFF_SET_BETWEEN_UPPER_AND_LOWER = 32; if(c >= 'a' && c <='z') { c = c - OFF_SET_BETWEEN_UPPER_AND_LOWER; } } bool sameStringsIgnoreCase(const char s[], const char s2[]) { bool result = true; int i = 0; if(strlen(s) == strlen(s2)) { while(s[i] != '\0') { //char c = s[i]; //char c2 = s2[i]; //MakeUpperCase(c); //c2 = toupper(c2); if(toupper(s[i]) != toupper(s2[i])) { result = false; } i++; } } else { result = false; } return result; } bool sameStrings(const char s[], const char s2[]) { bool result = true; int i = 0; if(strlen(s) == strlen(s2)) { while(s[i] != '\0') { if(s[i] != s2[i]) { result = false; } i++; } } else { result = false; } return result; } void main() { char s[100]; char s2[100]; cin.getline(s,100); cin.getline(s2,100); //if( sameStrings(s, s2) ) //if( sameStringsIgnoreCase(s, s2) ) //strcmp returns an integer // 0 - if the two strings are "equal" // >0 - if s > s2 // <0 - if s < s2 //if( stricmp(s, s2) == 0 ) if( strnicmp(s, s2, 3) == 0 ) { cout << "They are the same" << endl; } else { cout << "They are NOT the same" << endl; } // cout << "stricmp(s, s2) = " << stricmp(s, s2)<< endl; // cout << "strncmp(s, s2,3) = " << strncmp(s, s2,3)<< endl; cout << "strnicmp(s, s2,3) = " << strnicmp(s, s2,3)<< endl; }